/*
 *  MyComboBoxRenderer.java
 *
 * Copyright 2011 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Creado el 05/04/2011, 11:23:38 AM
 */

package com.ufps.cuatro.util.render;

import com.ufps.cuatro.modelo.representacion.componente.ComponenteDistribuidor;
import java.awt.Component;
import java.io.Serializable;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 * <i><b>MyComboBoxRenderer:</b></i> @DefinicionClase
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 05/04/2011
 * @see JComboBox
 * @see TableCellRenderer
 * @see Serializable
 */
public class MyComboBoxRenderer extends JComboBox implements TableCellRenderer, Serializable {
    private static final long serialVersionUID = 395612013386846649L;
    /**
     *@DefinicionMetodo
     * @param items @DefinicionParametro
     */
    public MyComboBoxRenderer(Object[] items) {
        super(items);
    }

    public MyComboBoxRenderer() {
    }

    public MyComboBoxRenderer(ComboBoxModel<Object> aModel) {
        super(aModel);
    }
    
    

//    MyComboBoxRenderer(ObjetoGenerador objGUI, Object[] toArray) {
//        super(toArray);
//    }
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        try{
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                super.setBackground(table.getSelectionBackground());
            }
            else {
                setForeground(table.getForeground());
                setBackground(table.getBackground());
            }
            // Select the current value
            if(value instanceof ComponenteDistribuidor){
                ComponenteDistribuidor objComponenteDistribuidor = (ComponenteDistribuidor) value;
                setSelectedItem(objComponenteDistribuidor.getStrPaquete());
            }
            else{
                setSelectedItem(value);
            }
            return this;
    }catch(java.lang.Exception ex){}
        return null;
    }
}

